package com.huike.report.mapper;

import java.util.List;
import java.util.Map;

import com.huike.report.domain.vo.BusinessChangeVO;
import com.huike.report.domain.vo.BusinessChangeVO;
import com.huike.report.domain.vo.VulnerabilityMapVo;
import org.apache.ibatis.annotations.Param;

import org.apache.ibatis.annotations.Select;

/**
 * 首页统计分析的Mapper
 *
 * @author Administrator
 */
public interface ReportMapper {
    /**=========================================基本数据========================================*/
    /**
     * 获取线索数量
     *
     * @param beginCreateTime 开始时间
     * @param endCreateTime   结束时间
     * @param username        用户名
     * @return
     */
    Integer getCluesNum(@Param("startTime") String beginCreateTime,
                        @Param("endTime") String endCreateTime,
                        @Param("username") String username);

    /**
     * 获取商机数量
     *
     * @param beginCreateTime 开始时间
     * @param endCreateTime   结束时间
     * @param username        用户名
     * @return
     */
    Integer getBusinessNum(@Param("startTime") String beginCreateTime,
                           @Param("endTime") String endCreateTime,
                           @Param("username") String username);

    /**
     * 获取合同数量
     *
     * @param beginCreateTime 开始时间
     * @param endCreateTime   结束时间
     * @param username        用户名
     * @return
     */
    Integer getContractNum(@Param("startTime") String beginCreateTime,
                           @Param("endTime") String endCreateTime,
                           @Param("username") String username);

    /**
     * 获取合同金额
     *
     * @param beginCreateTime 开始时间
     * @param endCreateTime   结束时间
     * @param username        用户名
     * @return
     */
    Double getSalesAmount(@Param("startTime") String beginCreateTime,
                          @Param("endTime") String endCreateTime,
                          @Param("username") String username);


    /**
     * =========================================今日简报========================================
     */
    @Select("select count(id) as businessNum from tb_business where datediff(create_time,now())=0" +
            " and create_by=#{username}")
    Integer getTodayBusinessNum(String username);

    @Select("select count(id) as CluesNum from tb_clue where datediff(create_time,now())=0" +
            " and create_by=#{username}")
    Integer getTodayCluesNum(String username);

    @Select("select count(id) as ContractNum from tb_contract where datediff(create_time,now())=0" +
            " and create_by=#{username}")
    Integer getTodayContractNum(String username);

    @Select("select Round(SUM(contract_order),2)  as SalesAmount from tb_contract where datediff(create_time,now())=0" +
            " and create_by=#{username}")
    Double getTodaySalesAmount(String username);

    List<BusinessChangeVO> getRanking(@Param("startTime") String beginCreateTime, @Param("endTime") String endCreateTime);

    /**
     * =========================================统计分析-客户统计-学科客户分布饼图========================================
     */
    List<Map<String, String>> subjectStatistics(@Param("beginCreateTime") String beginCreateTime, @Param("endCreateTime") String endCreateTime);

    /**
     * =========================================今日简报========================================
     */

    String getDeptName(String create_by);

    Integer getBusinessNumBy(@Param("startTime") String beginCreateTime, @Param("endTime") String endCreateTime, @Param("username") String createBy);

    VulnerabilityMapVo getVulnerabilityMap(@Param("beginCreateTime") String beginCreateTime, @Param("endCreateTime") String endCreateTime, @Param("userName") String userName);


    /**=========================================待办========================================*/

    Integer getCluesNum1(@Param("beginCreateTime") String beginCreateTime,
                         @Param("endCreateTime") String endCreateTime,
                         @Param("username") String username);

    Integer getBusinessNum1(@Param("beginCreateTime") String beginCreateTime,
                            @Param("endCreateTime") String endCreateTime,
                            @Param("username") String username);

    Integer getContractNum1(@Param("beginCreateTime") String beginCreateTime,
                            @Param("endCreateTime") String endCreateTime,
                            @Param("username") String username);
@Select("SELECT COUNT(id) FROM tb_business where DATE_FORMAT(create_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{beginCreateTime}, '%Y-%m-%d') AND DATE_FORMAT(#{endCreateTime}, '%Y-%m-%d') AND status = 1 or status = 3")
    Integer getSalesAmount1(@Param("beginCreateTime") String beginCreateTime,
                            @Param("endCreateTime") String endCreateTime,
                            @Param("username") String username);





}
